﻿@model List<TruckWatch.Cloud.Models.EF.Message>
@{
    string userid = Request.QueryString["UserId"] == null ? "(no driver specified)" : Request.QueryString["UserId"].ToString();
    ViewBag.Title = "Messages for " + userid;
}
@Html.DropDownList("id", HtmlUtil.RenderDrivers(userid, true), new { onchange = "redirectToInboundMessages(this.value)" })<br />
<br />
<h3>Inbound Messages</h3>
@(Html.Telerik().Grid(Model).Name("Messages")
    .DataKeys(k => k.Add(c => c.Id))
    .Columns(columns =>
    {
        columns.Bound(c => c.Id).Title("MsgId");
        columns.Bound(c => c.SenderDriver.Name).Title("Sender");
        columns.Bound(c => c.MessageType);
        columns.Bound(c => c.MessageText);
        columns.Bound(c => c.SendDate);
        columns.Bound(c => c.ParentMessageId);
        columns.Bound(c => c.ResponderDistance).Title("Responder Distance (miles)").Format("{0:0.0}");
        columns.Template(o => { }).Title("yes").HeaderHtmlAttributes(new { style = "color:rgb(241, 245, 251)" });
        columns.Template(o => { }).Title("no").HeaderHtmlAttributes(new { style = "color:rgb(241, 245, 251)" });
    })
    .CellAction(c =>
    {
        if (c.DataItem.MessageType == "Distress" && (c.Column.Title == "yes" || c.Column.Title == "no"))
            c.Text = Html.ActionLink("Respond " + c.Column.Title, "DistressResponse", new { ParentMessageId = c.DataItem.Id, ResponderUserId = userid, DistressedDriverId = c.DataItem.SenderDriverId, Response = c.Column.Title }).ToHtmlString();
        if (c.Column.Title == "Message Type")
        {
            if (!c.HtmlAttributes.ContainsKey("style"))
                c.HtmlAttributes.Add("style", "color:brown");
        }
    })
    .Footer(false)
)
<br />
<h3>Outbound Messages</h3>

@(Html.Telerik().Grid<TruckWatch.Cloud.Models.EF.Message>((List<TruckWatch.Cloud.Models.EF.Message>)ViewBag.OutboundMessages)
.Name("OutboundMessages")
    .DataKeys(k => k.Add(c => c.Id))
    .Columns(columns =>
    {
        columns.Bound(c => c.Id).Title("MsgId");
        columns.Bound(c => c.SenderDriver.Name).Title("Sender");
        columns.Bound(c => c.RecipientDriver.Name).Title("Recipient");
        columns.Bound(c => c.MessageType);
        columns.Bound(c => c.MessageText);
        columns.Bound(c => c.SendDate);
        columns.Bound(c => c.ParentMessageId);
        columns.Bound(c => c.ResponderDistance).Title("Responder Distance (miles)").Format("{0:0.0}");
    })
    .CellAction(c =>
    {
        if (c.Column.Title == "Message Type")
        {
            if (!c.HtmlAttributes.ContainsKey("style"))
                c.HtmlAttributes.Add("style", "color:brown");
        }
    })
    .Footer(false)
)
    